#ifndef GPSSIMULATOR_H
#define GPSSIMULATOR_H
#include "socket/protocol/gps.h"
#include <string.h>
class GPSSimulator
{
public:
    GPSSimulator();
    void setStartEndPos(unsigned int startLat,unsigned int startLon, unsigned int endLat,unsigned int endLon)
    {
        startPos.lat = startLat;
        startPos.lon = startLon;
        startPos.time = 0;
        endPos.lat = endLat;
        endPos.lon = endLon;
        endPos.time = 0;

        clientPos.lat = startPos.lat - 500000;
        clientPos.lon = startPos.lon - 500000;
        clientPos.time = 0;
        carPos.lat = startPos.lat + 500000;
        carPos.lon = startPos.lon + 500000;
        carPos.time = 0;

        latStep = (endLat - startLat)/10;
        lonStep = (endLon - startLon)/10;
        stepCount = 0;
    }
    void setOrderId(char * id)
    {
        memcpy(order_id,id,10);
    };
    void CarMoveStart()
    {
        carPos.lat = startPos.lat;
        carPos.lon = startPos.lon;
    }
    bool CarMoving()
    {
        if(stepCount == 10)
        {
            carPos.lat = endPos.lat;
            carPos.lon = endPos.lon;
            return false;
        }

        carPos.lat += latStep;
        carPos.lon += lonStep;
        ++stepCount;
        return true;

    }
    bool CalcNextClientPos()
    {
        if(clientPos.lat == startPos.lat && clientPos.lon == startPos.lon)
        {
            return false;
        }
        else
        {
            clientPos.lat += 100000;
            clientPos.lon += 100000;
            return true;
        }
    };
    bool CalcNextCarPos()
    {
        if(carPos.lat == startPos.lat && carPos.lon == startPos.lon)
        {
            return false;
        }
        else
        {
            carPos.lat -= 100000;
            carPos.lon -= 100000;
            return true;
        }
    };
    void UpdateClientPos(unsigned int lat, unsigned int lon)
    {
        clientPos.lat = lat;
        clientPos.lon = lon;
    }
    void UpdateCarPos(unsigned int lat, unsigned int lon)
    {
        carPos.lat = lat;
        carPos.lon = lon;
    }
public:
    char order_id[10];
    protocal::GPS clientPos;
    protocal::GPS carPos;
    protocal::GPS startPos;
    protocal::GPS endPos;
    int latStep;
    int lonStep;
    int stepCount;

};



#endif // GPSSIMULATOR_H
